﻿
function getd3dcsxdlls([string]$filename,[string] $folderName)
{
    New-Item -ItemType Directory -Force -Path (Join-Path $DownloadsPath $folderName)
    $file = Join-Path $DownloadsPath  $filename 

    # download the file (version 2.2 is current at the time of writing)
    $result = $wc.DownloadFile("http://h-quer.de/files/stuff/d3dcsx_47.zip",$file)

    # unzip the file
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($file)
    foreach($item in $zip.items())
    {
        $shell.Namespace((Join-Path $DownloadsPath $folderName)).copyhere($item)
    }

    $folderToCopy = (Join-Path $DownloadsPath $folderName)
    $destFolder = Join-Path $WorkPath "..\FTLib\D3DCSX\"

    # make destination folder (if it does not exists) and copy the extracted files into this
    New-Item -ItemType Directory -Force -Path $destFolder 

    Copy-Item (Join-Path $folderToCopy  "\*") $destFolder -Recurse

}

#$local = Get-Location;

# get the path where this script resides
$WorkPath = split-path $MyInvocation.MyCommand.Definition -Parent

# that's the folder where we want to place the downloads and extract the ZIPs
$DownloadsPath = Join-Path $WorkPath "Downloads"

# empty and remove folder if it exists, then create a new one
If (Test-Path $DownloadsPath)
{
    Remove-Item $DownloadsPath -Force -Recurse
}

New-Item -ItemType Directory -Force -Path $DownloadsPath

$wc = New-Object system.Net.WebClient;


getd3dcsxdlls "d3dcsx_47.zip"  "d3dcsx"

